<?php
/**
 * APP用户缓存类
 * panglishan
 * 2020.09.02
 */
namespace App\Services\Cache;

use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;   //引入基础缓存类
use App\Exceptions\BasicException;     //引入异常处理类

class UserCacheService{


    const ONLINE_USER_KEY = 'api_online:user';
    const ONLINE_USER_TIME_KEY = 'api_online:user_time';
    const ONLINE_USER_TODAY_TIME_KEY = 'api_online:user_today_time';

    //获取在线用户数组
    static function getOnlineUserArr()
    {
        $online_arr = [];

        $user_key = self::ONLINE_USER_KEY;

        $time = time();

        $online_user = app('redis')->zrangebyscore($user_key,$time,"+inf");

        if(!empty($online_user)) $online_arr = array_values($online_user);

        return $online_arr;

    }

    //获取在线用户数据
    static function getOnlineUserCount($time)
    {
        $user_key = self::ONLINE_USER_KEY;

        $online_user = app('redis')->zrangebyscore($user_key,$time,"+inf");

        return count($online_user);

    }

}